import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomBroker } from '@/shared/model/room-broker.model';
import RoomBrokerService from './room-broker.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomBrokerDetails extends Vue {
  @Inject('roomBrokerService') private roomBrokerService: () => RoomBrokerService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomBroker: IRoomBroker = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomBrokerId) {
        vm.retrieveRoomBroker(to.params.roomBrokerId);
      }
    });
  }

  public retrieveRoomBroker(roomBrokerId) {
    this.roomBrokerService()
      .find(roomBrokerId)
      .then(res => {
        this.roomBroker = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
